|
|
 |
|
|
|
|
' If the device does not support palettes, quit. If Not GetDeviceCaps(hDC, RASTERCAPS) And RC_PALETTE Then
MsgBox "This device is not using palettes."
End
End If |
|
|
|
|
|
|
|
|
GetDeviceCaps returns the size of the system palette if you pass it the flag SIZEPALETTE. It returns the number of reserved static colors in the system palette if you use the flag NUMRESERVED. Half of the static colors lie in the first system palette entries, and half lie in the last. These numbers can be useful when you work with palettes. |
|
|
|
 |
|
|
|
|
Const SIZEPALETTE = 104 ' Size of system palette.
Const NUMRESERVED = 106 ' # reserved entries in palette.
' See how big the system palette is. SysPalSize = GetDeviceCaps(hDC, SIZEPALETTE)
' See how many static colors there are. NumStaticColors = GetDeviceCaps(hDC, NUMRESERVED |
|
|
|
|
|
|
|
|
Example program DevInfo uses GetDeviceCaps to display many of the capabilities of your computer's display. Keep in mind that Visual Basic may be able to provide a feature even though GetDeviceCaps indicates the hardware cannot. For example, in the unlikely event that your hardware cannot draw circles, Visual Basic may be able to draw circles itself. |
|
|
|
|
|
|
|
|
Palette Handles in Visual Basic |
|
|
|
|
|
|
|
|
So far, this chapter has described ways you can use the entries in a logical palette, but it has not explained how you can create or modify such a palette. The Windows API provides several functions for manipulating palettes. Many of these functions take as a parameter a handle to a palette object. To make working with these functions easier, Visual Basic gives you a way to access the palette handle for forms, image controls, and picture boxes that have them. |
|
|
|
|
|
|
|
|
Each of these objects has a Picture property. This property is actually a reference to a Picture object that has its own properties and methods. One of those properties is hPal, a handle to the logical palette used by the object. You can use Windows API routines and this handle to manipulate the palette. |
|
|
|
|
|
|
|
|
It is important to know, however, that objects do not always have pictures or logical palettes. If you create a picture box and draw on it using methods like Circle and Line, the drawing object's Picture property still has the value zero. Because the Picture property does not contain a reference to a Picture object, you cannot use that object's hPal property. If you try to access the hPal property for the nonexistent Picture object, you get the rather enigmatic run-time error '2147483640 (80000008)': OLE Automation error. |
|
|
|
|
|
|
|
|
You can give a drawing object a valid Picture property by setting AutoRedraw to True, drawing on the object, and then setting its Picture property equal to its Image property as in the following code. |
|
|
|
|
|